package de.doegel.common.widget;

import greendroid.widget.item.Item;
import greendroid.widget.itemview.ItemView;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import de.doegel.common.R;

public class HeadedContactItemView extends LinearLayout implements ItemView {
	public TextView headerView;
	public TextView textView;
	public ImageView imageView;

	public HeadedContactItemView(Context context) {
		this(context, null);
	}

	public HeadedContactItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void prepareItemView() {
		headerView = (TextView) findViewById(R.id.gd_separator_text);
		textView = (TextView) findViewById(R.id.gd_text);
		imageView = (ImageView) findViewById(R.id.contact_image);
		imageView.setImageResource(R.drawable.empty_contact_image);
	}

	public void setObject(Item object) {
		final HeadedContactItem item = (HeadedContactItem) object;
		final String headerText = item.headerText;

		if (!TextUtils.isEmpty(headerText)) {
			headerView.setText(headerText);
			headerView.setVisibility(View.VISIBLE);
		} else {
			headerView.setVisibility(View.GONE);
		}

		textView.setText(item.text);
	}

}
